package com.example.redis.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author void
 * @date 2021/6/3 11:33
 * @desc
 */
@Slf4j
//@Component
public class StartRunner implements CommandLineRunner {
    @Autowired
    private RedisTemplate fastRedisTemplate;

    @Override
    public void run(String... args) throws Exception {
        while(true){
            log.debug("命令行开机自启动定时消费");
            String key = "key_list2";
            ListOperations<String, Integer> operations = fastRedisTemplate.opsForList();
            Integer num = operations.leftPop(key);
            if(num!=null){
                log.debug("命令行开机自启动消费元素:{}", num);
            }
            Thread.sleep(1000);
        }
    }
}
